package com.tinckay.common.util;

import cn.hutool.core.util.RandomUtil;
import org.springframework.util.DigestUtils;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.LocalDateTime;
import java.util.Random;

/**
 * @Author: Jean
 * @Desc: 常用方法工具类
 * @Date: 2018/10/23 11:22
 */
public class ToolUtils {

    /**
     * 创建StringBuilder对象
     *
     * @return StringBuilder对象
     */
    public static StringBuilder builder(String... strs) {
        final StringBuilder sb = new StringBuilder();
        for (String str : strs) {
            sb.append(str);
        }
        return sb;
    }

    /**
     * 创建StringBuilder对象
     *
     * @return StringBuilder对象
     */
    public static void builder(StringBuilder sb, String... strs) {
        for (String str : strs) {
            sb.append(str);
        }
    }

    /**
     * 当前时间
     *
     * @Date 2017/5/7 21:56
     */
    public static LocalDateTime currentTime() {
        return LocalDateTime.now();
    }

    /**
     * 生成4位数手机验证码
     */
    public static int getValidCode() {
        return (int) (Math.random() * 9000) + 1000;
    }

    public static String getExceptionMsg(Throwable e) {
        StringWriter sw = new StringWriter();

        try {
            e.printStackTrace(new PrintWriter(sw));
        } finally {
            try {
                sw.close();
            } catch (IOException var8) {
                var8.printStackTrace();
            }

        }

        return sw.getBuffer().toString().replaceAll("\\$", "T");
    }

}
